using GroupSix.Domain.Entity.App;
using GroupSix.Domain.common;

namespace GroupSix.Domain.Repositories;

/// <summary>
/// 操作日志查询DTO
/// </summary>
public class OperationLogQueryDto
{
    /// <summary>
    /// 操作人ID
    /// </summary>
    public Guid? OperatorId { get; set; }

    /// <summary>
    /// 操作人用户名（模糊查询）
    /// </summary>
    public string? OperatorName { get; set; }

    /// <summary>
    /// 操作类型
    /// </summary>
    public string? OperationType { get; set; }

    /// <summary>
    /// 操作模块
    /// </summary>
    public string? Module { get; set; }

    /// <summary>
    /// 操作结果
    /// </summary>
    public string? Result { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// IP地址（模糊查询）
    /// </summary>
    public string? IpAddress { get; set; }

    /// <summary>
    /// 页码
    /// </summary>
    public int Page { get; set; } = 1;

    /// <summary>
    /// 页大小
    /// </summary>
    public int PageSize { get; set; } = 20;
}
/// 操作日志仓储接口
/// </summary>
public interface IOperationLogRepository : IRepository<GsOperationLog>
{
    /// <summary>
    /// 根据操作人获取日志列表
    /// </summary>
    /// <param name="operatorId">操作人ID</param>
    /// <param name="page">页码</param>
    /// <param name="pageSize">页大小</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetLogsByOperatorAsync(Guid operatorId, int page = 1, int pageSize = 20);

    /// <summary>
    /// 根据操作类型获取日志列表
    /// </summary>
    /// <param name="operationType">操作类型</param>
    /// <param name="page">页码</param>
    /// <param name="pageSize">页大小</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetLogsByOperationTypeAsync(string operationType, int page = 1, int pageSize = 20);

    /// <summary>
    /// 根据模块获取日志列表
    /// </summary>
    /// <param name="module">模块</param>
    /// <param name="page">页码</param>
    /// <param name="pageSize">页大小</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetLogsByModuleAsync(string module, int page = 1, int pageSize = 20);

    /// <summary>
    /// 根据时间范围获取日志列表
    /// </summary>
    /// <param name="startTime">开始时间</param>
    /// <param name="endTime">结束时间</param>
    /// <param name="page">页码</param>
    /// <param name="pageSize">页大小</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetLogsByTimeRangeAsync(DateTime startTime, DateTime endTime, int page = 1, int pageSize = 20);

    /// <summary>
    /// 获取最近的日志列表
    /// </summary>
    /// <param name="page">页码</param>
    /// <param name="pageSize">页大小</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetRecentLogsAsync(int page = 1, int pageSize = 20);

    /// <summary>
    /// 根据条件查询日志
    /// </summary>
    /// <param name="query">查询条件</param>
    /// <returns>日志列表</returns>
    Task<PageResult<GsOperationLog>> GetLogsByConditionAsync(OperationLogQueryDto query);

    /// <summary>
    /// 导出日志
    /// </summary>
    /// <param name="query">查询条件</param>
    /// <returns>日志数据</returns>
    Task<List<GsOperationLog>> ExportLogsAsync(OperationLogQueryDto query);

    /// <summary>
    /// 清理过期日志（只读保护，实际不删除，只标记）
    /// </summary>
    /// <param name="beforeDate">清理此日期之前的日志</param>
    /// <returns>清理数量</returns>
    Task<int> CleanupExpiredLogsAsync(DateTime beforeDate);

    /// <summary>
    /// 获取日志统计信息
    /// </summary>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns>统计信息</returns>
    Task<object> GetLogStatisticsAsync(DateTime? startDate = null, DateTime? endDate = null);

    /// <summary>
    /// 获取总日志数
    /// </summary>
    /// <returns>总日志数</returns>
    Task<int> GetTotalLogsCountAsync();

    /// <summary>
    /// 获取过期日志数量
    /// </summary>
    /// <param name="beforeDate">过期日期</param>
    /// <returns>过期日志数量</returns>
    Task<int> GetExpiredLogsCountAsync(DateTime beforeDate);
} 